package com.mes.md.controller;

import com.mes.common.pojo.MESResult;
import com.mes.md.service.WorkshopService;
import com.mes.pojo.md.MdWorkshop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/10/24 16:48
 */

@RestController
@RequestMapping("/workshop")
@CrossOrigin
public class WorkshopController {
    @Autowired
    private WorkshopService workshopService;

    @GetMapping("/query")
    public MESResult queryWorkshop(MdWorkshop workshop)
    {
        List<MdWorkshop> workshops = workshopService.queryWorkshop(workshop);
        System.out.println(workshops);
        return MESResult.success(workshops);
    }

    @DeleteMapping("/delete")
    public MESResult deleteWorkshop(String workshopId)
    {
        Integer result = workshopService.deleteWorkshop(workshopId);
        return MESResult.success(result);
    }

    @GetMapping("/queryById")
    public MESResult queryWorkshopById(String workshopId)
    {
        MdWorkshop workshop = workshopService.queryWorkshopById(workshopId);
        return MESResult.success(workshop);
    }

    @PostMapping("/update")
    public MESResult updateWorkshop(@RequestBody MdWorkshop workshop)
    {
        System.out.println(workshop);
        Integer result = workshopService.updateWorkshop(workshop);
        return MESResult.success(result);
    }

    @PostMapping("/insert")
    public MESResult insertWorkshop(@RequestBody MdWorkshop workshop)
        {
        Integer result = workshopService.insertWorkshop(workshop);
        return MESResult.success(result);
    }
}
